/**
 * 
 */
package com.yufei.infoExtractor.extractor;

import java.io.File;



import java.io.IOException;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

import junit.framework.Assert;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.lucene.util.ArrayUtil;

import com.yufei.infoExtractor.core.LinkAction;
import com.yufei.infoExtractor.core.LinkActionForMedia;
import com.yufei.infoExtractor.extractor.propertyExtractor.PropertyExtractorFactory;
import com.yufei.infoExtractor.listener.EventType;
import com.yufei.infoExtractor.listener.InfoExtractorEvent;
import com.yufei.infoExtractor.listener.InfoExtractorListener;
import com.yufei.infoExtractor.parallel.ParallelThreadExecutor;
import com.yufei.infoExtractor.parallel.executor.UrlFetchParallelThreadExecutor;
import com.yufei.infoExtractor.parallel.thread.UrlFetchThread;
import com.yufei.infoExtractor.pfw.InfoExtractorDao;
import com.yufei.infoExtractor.pfw.entity.PropertyMatch;
import com.yufei.infoExtractor.pfw.entity.Relatedlink;
import com.yufei.infoExtractor.pfw.mongodb.DataRepository;
import com.yufei.infoExtractor.util.AppUtil;
import com.yufei.infoExtractor.util.CommonUtil;
import com.yufei.infoExtractor.util.EncryptUtil;
import com.yufei.infoExtractor.util.ExceptionUtil;
import com.yufei.infoExtractor.util.HtmlUtil;
import com.yufei.infoExtractor.util.PatternUtils;
import com.yufei.infoExtractor.util.sequence.SequenceUUID;

/**
 * @author zhaoyufei zhao-0244@qq.com
 * 对文本内容进行加工分析抽取符合目标信息
 * created at 2012-8-14 下午1:32:24
 */
public class ContentExtractor extends Extractor implements InfoExtractorListener {
	public ContentExtractor() {
		super();
		// TODO Auto-generated constructor stub
	}

	public static final Log mLog = LogFactory.getLog(ContentExtractor.class);

	/* 
	 * @see com.rzx.crawler.extractor.ExtractorAction#extract(java.util.Map)
	 */
	@Override
	public void extract(final Map context) {
	
		Integer currentDepth = (Integer) context.get("currentDepth");
		Set[] linkSet = (Set[]) context.get("linkSet");
       
		final Set<String> readyUrlList=linkSet[currentDepth];
		Set<String> linkFingerPrints=(Set<String>) context.get("linkFingerPrints");
		
		int totalUrlSize = readyUrlList.size();
		if(totalUrlSize==0){
			return;
			
		}
	 
			
           

		
				int blockSize=50;


				ParallelThreadExecutor parallelThreadExecutor=new UrlFetchParallelThreadExecutor();
			
				parallelThreadExecutor.parallelExecuteThreadsForCollectionData(readyUrlList, blockSize, context);
					
			}
				
			
	    		
	    	








	
	@Override
	public void actionPerformed(InfoExtractorEvent event) {
		// TODO Auto-generated method stub
		if(!(event.getEventType()==EventType.CONTENTEXTRACTOR)){
			return;
		}
		Map<String,Object> context=(Map<String, Object>) event.getSource();
		this.extract(context);
		//获取当前层
		//获取当前层链接列表
		//对当前层的链接列表进行内容抽取以及保存
		
	}

	

}
